package com.huawei.fastengine.fastview.download.install;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.text.TextUtils;
import com.huawei.fastengine.fastview.download.utils.CommonUtils;
import com.huawei.fastengine.fastview.download.utils.log.FastViewLogUtils;
import o.ll;

public class PackageInstallerActivity extends Activity {
    public static final String INSTALL_CHANGE_PATH_TIMES = "install_change_path_times";
    public static final String INSTALL_EXISTING = "install_existing";
    public static final String INSTALL_PACKAGENAME = "install_packagename";
    public static final String INSTALL_PATH = "install_path";
    private static final int REQUEST_INSTALL_CODE = 100;
    private static final String TAG = "PackageInstallerActivity";
    private static final String TASK_INSTALL_EXISTING = "installExisting:";
    private int changePathTimes = -1;
    private String filePath = "";
    private boolean installExisting = false;
    private String packageName = "";
    private String taskIdCacheKey = "";

    protected void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        FastViewLogUtils.d(PackageManagerConstants.TAG, "PackageInstallerActivity onActivityResult requestCode:" + i + ",resultCode:" + i2);
        if (100 == i && i2 == 0) {
            FastViewLogUtils.d(TAG, "userCancel");
            ll.ˏ(this).ˋ(new Intent("action_install_info_fail"));
        }
        finish();
    }

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        Intent intent = getIntent();
        if (intent == null || CommonUtils.hasParseException(intent)) {
            finish();
            FastViewLogUtils.e(PackageManagerConstants.TAG, "PackageInstallerActivity error intent");
            return;
        }
        this.filePath = intent.getStringExtra(INSTALL_PATH);
        this.packageName = intent.getStringExtra(INSTALL_PACKAGENAME);
        this.installExisting = intent.getBooleanExtra(INSTALL_EXISTING, false);
        if (TextUtils.isEmpty(this.filePath)) {
            finish();
            FastViewLogUtils.e(PackageManagerConstants.TAG, "PackageInstallerActivity can not find filePath.");
            return;
        }
        this.changePathTimes = intent.getIntExtra(INSTALL_CHANGE_PATH_TIMES, -1);
        intent = VERSION.SDK_INT >= 24 ? InstallProcessSdk24.getNomalInstallIntent(this, this.filePath) : InstallProcess.getNomalInstallIntent(this, this.filePath);
        this.taskIdCacheKey = this.filePath;
        intent.putExtra("android.intent.extra.NOT_UNKNOWN_SOURCE", true);
        intent.putExtra("android.intent.extra.RETURN_RESULT", true);
        FastViewLogUtils.i(PackageManagerConstants.TAG, "PackageInstallerActivity onCreate filePath:" + this.filePath + ",packageName:" + this.packageName + ",taskId:" + getTaskId());
        try {
            startActivityForResult(intent, 100);
        } catch (ActivityNotFoundException e) {
            FastViewLogUtils.e(TAG, "can not start install action");
            finish();
        }
    }

    protected void onDestroy() {
        super.onDestroy();
        finishActivity(100);
        FastViewLogUtils.i(PackageManagerConstants.TAG, "PackageInstallerActivity onDestroy removeTaskId:" + this.filePath);
    }
}
